from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response

from order import models, orderser
# Create your views here.
from utils.authorization import MyAuth
from user.models import UserModel

class MyCoupon(APIView):
    def get(self,request):
        user=request.query_params.get('user')
        if not user:
            return Response({"msg":"请登录"})
        userinfo=UserModel.objects.filter(id=user).first()
        usercoupon=models.UserCoupon.objects.filter(user=user)
        ser=orderser.userCouponSerializer(instance=usercoupon,many=True)
        return Response({"coupon":ser.data,"credittomoney":10,"hascredit":userinfo.score})